import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wan_android_flutter/common_ui/web/webview_widget.dart';
import 'package:wan_android_flutter/pages/auth/login_page.dart';
import 'package:wan_android_flutter/pages/knowledge/detail/knowledge_detail_tab_page.dart';
import 'package:wan_android_flutter/pages/tab_page.dart';
import '../common_ui/web/webview_page.dart';
import '../pages/about_us/about_us_page.dart';
import '../pages/auth/register_page.dart';
import '../pages/my_collects/my_collects_page.dart';
import '../search/search_page.dart';

/// 路由管理类
class Routes {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case RoutePath.tab:
        return pageRoute(TabPage(), settings: settings);
      case RoutePath.webViewPage:
        return pageRoute(
            WebViewPage(
              loadResource: "",
              webViewType: WebViewType.URL,
            ),
            settings: settings);
      case RoutePath.loginPage:
        return pageRoute(LoginPage(), settings: settings);
      case RoutePath.registerPage:
        return pageRoute(RegisterPage(), settings: settings);
      case RoutePath.detailKnowledgePage:
        return pageRoute(knowledgeDetailTabPage(null), settings: settings);
      case RoutePath.searchPage:
        return pageRoute(SearchPage(), settings: settings);
      case RoutePath.myCollectsPage:
        return pageRoute(MyCollectsPage(), settings: settings);
      case RoutePath.aboutUsPage:
        return pageRoute(AboutUsPage(), settings: settings);
    }
    return pageRoute(Scaffold(
      body: SafeArea(
        child: Text("路由：${settings.name} 不存在"),
      ),
    ));
  }

  static MaterialPageRoute pageRoute(Widget page,
      {RouteSettings? settings,
      bool? fullscreenDialog,
      bool? maintainState,
      bool? allowSnapshotting}) {
    return MaterialPageRoute(
        builder: (context) {
          return page;
        },
        settings: settings,
        fullscreenDialog: fullscreenDialog ?? false,
        maintainState: maintainState ?? true,
        allowSnapshotting: allowSnapshotting ?? true);
  }
}

//路由地址
class RoutePath {
  //首页
  static const String tab = "/";

  //网页页面
  static const String webViewPage = "/web_view_page";

  //登录
  static const String loginPage = "/login_page";

  //注册
  static const String registerPage = "/register_page";

  //知识体系明细
  static const String detailKnowledgePage = "/detail_knowledge_page";

  //搜索页
  static const String searchPage = "/SearchPage";

  //我的收藏列表页
  static const String myCollectsPage = "/my_collects_page";

  //关于我们页面
  static const String aboutUsPage = "/about_us_page";
}
